$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'itcs/cpproadconf/list',
        datatype: "json",
        colModel: [
			{ label: 'id', name: 'id', index: 'id', width: 80, key: true },
			{ label: '所属路方', name: 'roadId', index: 'road_id', width: 50 },
			{ label: '收费站编号', name: 'stationId', index: 'station_id', width: 70 },
			{ label: '业务类型', name: 'bizType', index: 'biz_type', width: 40 },
			{ label: '接入渠道', name: 'payChannel', index: 'pay_channel', width: 40 },
			{ label: '支付方式', name: 'payType', index: 'pay_type', width: 40 },
			/*{ label: '协议号', name: 'contractNo', index: 'contract_no', width: 80 },
			{ label: '协议附件', name: 'contractFile', index: 'contract_file', width: 80 },
			{ label: '商户代码', name: 'merId', index: 'mer_id', width: 80 },*/
			{ label: '接入参数', name: 'params', index: 'params', width: 80 },
			{ label: '状态', name: 'status', index: 'status', width: 40 },
			/*{ label: '生效日期', name: 'startDate', index: 'start_date', width: 80 },
			{ label: '失效日期', name: 'endDate', index: 'end_date', width: 80 },
			{ label: '优先级', name: 'level', index: 'level', width: 80 },
			{ label: '权重', name: 'weight', index: 'weight', width: 80 },
			{ label: '操作人', name: 'operator', index: 'operator', width: 80 },
			{ label: '创建时间', name: 'createTime', index: 'create_time', width: 80 },
			{ label: '更新时间', name: 'updateTime', index: 'update_time', width: 80 },*/
			{ label: '插件名称', name: 'api', index: 'api', width: 80 }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		cppRoadConf: {},
        options: [
            { text: '自有钱包', value: '0' },
            { text: '银联支付', value: '1' },
            { text: '银联支付', value: '2' },
            { text: '支付宝支付', value: '3' },
            { text: '百度支付', value: '4' },
            { text: '京东支付', value: '5' },
            { text: '广发钱包', value: '6' },
            { text: 'ITC支付', value: '7' },
            { text: '尚高速支付', value: '8' },
            { text: '汇联通支付', value: '9' },
            { text: 'QQ钱包', value: '10' }
        ],
        payTypes: []
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.cppRoadConf = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
		    $('#btnSaveOrUpdate').button('loading').delay(1000).queue(function() {
                var url = vm.cppRoadConf.id == null ? "itcs/cpproadconf/save" : "itcs/cpproadconf/update";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.cppRoadConf),
                    success: function(r){
                        if(r.code === 0){
                             layer.msg("操作成功", {icon: 1});
                             vm.reload();
                             $('#btnSaveOrUpdate').button('reset');
                             $('#btnSaveOrUpdate').dequeue();
                        }else{
                            layer.alert(r.msg);
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        }
                    }
                });
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定','取消'] //按钮
            }, function(){
               if(!lock) {
                    lock = true;
		            $.ajax({
                        type: "POST",
                        url: baseURL + "itcs/cpproadconf/delete",
                        contentType: "application/json",
                        data: JSON.stringify(ids),
                        success: function(r){
                            if(r.code == 0){
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            }else{
                                layer.alert(r.msg);
                            }
                        }
				    });
			    }
             }, function(){
             });
		},
        enable: function (event) {
            var ids = getSelectedRows();
            if(ids == null){
                return ;
            }
            var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                if(!lock) {
                    lock = true;
                    $.ajax({
                        type: "POST",
                        url: baseURL + "itcs/cpproadconf/delete",
                        contentType: "application/json",
                        data: JSON.stringify(ids),
                        success: function(r){
                            if(r.code == 0){
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            }else{
                                layer.alert(r.msg);
                            }
                        }
                    });
                }
            }, function(){
            });
        },
        disable: function (event) {
            var ids = getSelectedRows();
            if(ids == null){
                return ;
            }
            var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                if(!lock) {
                    lock = true;
                    $.ajax({
                        type: "POST",
                        url: baseURL + "itcs/cpproadconf/delete",
                        contentType: "application/json",
                        data: JSON.stringify(ids),
                        success: function(r){
                            if(r.code == 0){
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            }else{
                                layer.alert(r.msg);
                            }
                        }
                    });
                }
            }, function(){
            });
        },
		getInfo: function(id){
			$.get(baseURL + "itcs/cpproadconf/info/"+id, function(r){
                vm.cppRoadConf = r.cppRoadConf;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});